<?php

namespace app\controller;

use app\traits\ControllerTrait;

class AdminTemplate extends ControllerTrait{

    /**
     * 所有模板列表
     */
    public function TemplateList(){
        $templateList = app('adminTemplateModel') ->select();
        foreach ($templateList as $value){
            $value -> specifications = explode(",",$value->specifications);
        }
        $this->success($templateList);
    }
    /**
     * 所有模板列表
     */
    public function AddTemplate(){

        $param = $this->request->param();
        $rule = [
            "name|模板名称" => "require",
            "specifications|规格-以逗号' , '分割" => "require",
        ];
        $this->validate($param, $rule);

        $template = app("adminTemplateModel")->where(['name' => $param['name'],])->find();

        if(empty($template)){
            $template = app("adminTemplateModel");
        }
        $template->save([
            'name' => $param['name'],
            'specifications' => $param['specifications'],
            'create_time' => time(),
        ]);
        $this->success(['msg' => '操作成功']);

    }
}